//
//  FDNonLoginView.m
//  FamousDoctorOnline
//
//  Created by wszyxc on 16/7/6.
//  Copyright © 2016年 wszyxc. All rights reserved.
//

#import "FDNonLoginView.h"

@interface FDNonLoginView ()

//用户头像
@property (weak,nonatomic) UIImageView * userImageView;
//登陆按钮
@property (weak,nonatomic) UIButton * loginBtn;
//注册按钮
@property (weak,nonatomic) UIButton * registerBtn;


@end


@implementation FDNonLoginView

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        [self setupUI];
        
    }
    return self;
}

- (void)layoutSubviews{
    
    [super layoutSubviews];
    
    [self setupUserImageViewLayout];
    
    [self setupLoginBtnLayout];
    
    [self setupRegisterBtnLayout];
    

    
}



- (void)setupUI{
    
    //1.设置headerView
    
    self.backgroundColor = kThemeColor;
    
    //2.实例化头像view
    UIImageView *userImageView = [[UIImageView alloc]init];
    
    self.userImageView = userImageView;
    
    userImageView.image = [[UIImage imageNamed:@"name"] circleImage];
    
    NSLog(@"%@",NSStringFromCGSize(userImageView.image.size));
    
    //添加头像
    [self addSubview:userImageView];
    
    
    //3.实例化loginBtn
    
    UIButton *loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    self.loginBtn = loginBtn;
    
    [loginBtn setTitle:@"登陆" forState:UIControlStateNormal];
    
    [loginBtn setTitleColor:WHITE_COLOR forState:UIControlStateNormal];
    
    loginBtn.titleLabel.font = [UIFont systemFontOfSize:18];
    
    [loginBtn addTarget:self action:@selector(loginClick) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:loginBtn];
    
    //4.实例化registerBtn

    UIButton *registerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.registerBtn = registerBtn;
    
    [registerBtn setTitle:@"注册" forState:UIControlStateNormal];
    
    [registerBtn setTitleColor:WHITE_COLOR forState:UIControlStateNormal];
    
    registerBtn.titleLabel.font = [UIFont systemFontOfSize:18];
    
    [registerBtn addTarget:self action:@selector(registerClick) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:registerBtn];
    
}

- (void)setupUserImageViewLayout{
    
    [self.userImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.mas_centerX);
        
        make.width.height.offset(70);
        
        make.top.offset(40);
        
    }];
    
}

- (void)setupLoginBtnLayout{
    
    [self.loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.offset(-10);
        make.trailing.equalTo(self.userImageView.mas_leading).offset(-20);
        
    }];
    
}

- (void)setupRegisterBtnLayout{
    
    [self.registerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.leading.equalTo(self.userImageView.mas_trailing).offset(20);
        make.bottom.offset(-10);
        
    }];
    
}


/**
 *  点击登陆
 */
- (void)loginClick{
    NSLog(@"点击了登陆");
    
    if (self.nonLoginViewBlock) {
        
        self.nonLoginViewBlock(self.loginBtn);
        
    }
    
}

/**
 *  点击注册
 */
- (void)registerClick{
    
    NSLog(@"点击了注册");
    
    if (self.nonLoginViewBlock) {
        self.nonLoginViewBlock(self.registerBtn);
    }
    
}


@end
